package com.aaa.controller;

import com.aaa.entity.YzhUser;
import com.aaa.service.YzhUserService;

import com.aaa.util.LayData;
import com.github.pagehelper.PageInfo;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (YzhUser)表控制层
 *
 * @author makejava
 * @since 2023-06-05 09:34:00
 */
@RestController
@RequestMapping("yzhUser")
public class YzhUserController {
    /**
     * 服务对象
     */
    @Resource
    private YzhUserService yzhUserService;



    /**
     * 新增数据
     *
     * @param yzhUser 实体
     * @return 新增结果
     *
     * post请求
     */
    @PostMapping
    public LayData add(YzhUser yzhUser) {
        YzhUser insert = this.yzhUserService.insert(yzhUser);
        return LayData.success(insert);
    }

    // 分页 查询出所有的数据  数据的总条数
    // 分页的插件   pageHelper
// 个体请求
    @GetMapping
    public LayData query(Integer page,Integer limit,YzhUser user){
        System.out.println("请求了查询所有的user的方法");
        PageInfo allByPage = this.yzhUserService.findAllByPage(page, limit,user);
        System.out.println("allByPage = " + allByPage);
        return LayData.success(allByPage.getTotal(),allByPage.getList());

    }

    // delete 请求

    // deleMapping
    // yzhUser/1
    @DeleteMapping("{id}")
    public LayData deleUser(@PathVariable Integer id){
        //
        boolean b = this.yzhUserService.deleteById(id);
        return LayData.success(b);

    }

    // 修改 根据id  进行修改


    @PutMapping
    public LayData update(YzhUser user){

        System.out.println("user = " + user);
        // 修改数据
        YzhUser update = this.yzhUserService.update(user);
        return LayData.success(update);

    }




}

